import os

import errno
import numpy as np

def assert_eq(real, expected):
    assert real == expected, '%s (true) vs %s (expected)' % (real, expected)


def create_dir(output):
    '''
    创建文件夹
    Args:
        output(str): path of directory

    Returns:

    '''
    if not os.path.exists(output):
        try:
            os.makedirs(output)
        except OSError as exc:
            if exc.errno != errno.EEXIST:
                raise


class Logger(object):
    def __init__(self, output_name):
        super(Logger, self).__init__()
        dirname = os.path.dirname(output_name)
        if not os.path.exists(dirname):
            os.mkdir(dirname)

        self.log_file = open(output_name, 'w')
        self.infos = {}


    def write(self, msg):
        self.log_file.write(msg + '\n')
        self.log_file.flush()
        print(msg)


        